package com.yh.exception;


import com.yh.common.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author yh
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = BaseException.class)
    public BaseResult bizExceptionHandler(HttpServletRequest req, BaseException e){
        logger.error("发生业务异常！原因是：{}",e.getMessage());
        return BaseResult.build(e.getCode(),e.getMessage());
    }
}
